package proyecto;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import clases.HtmlUtil;


@WebServlet("/inicio")
public class Inicio extends HttpServlet {

	private HtmlUtil util = new HtmlUtil();

	private static final long serialVersionUID = 1L;

	public Inicio() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter(); //donde iremos escribiendo los datos que queremos que el cliente reciba

		response.setContentType("text/html"); //para establecer el tipo de respuesta que vamos a dar

		String filename = "/WEB-INF/header.html" ; 
		ServletContext context = getServletContext(); 
		String pathname = context.getRealPath(filename);
		out.print(util.obtenerHTML(pathname));

		String par = request.getParameter("web");

		if (par != null){			
			filename = "/WEB-INF/" + par ; 
			context = getServletContext(); 
			pathname = context.getRealPath(filename);
			out.print(util.obtenerHTML(pathname));
		}

		filename = "/WEB-INF/footer.html" ; 
		context = getServletContext(); 
		pathname = context.getRealPath(filename);
		out.print(util.obtenerHTML(pathname));
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
